<template>
	<view class="content">
		<view class="integral_top">
			<view class="integral_money">
				<view >
					我的积分
				</view>
				<view>
					{{userinfo.userIntegral||0}}
				</view>
			</view>
			<view class="exchange">
				<image src="../../static/img/lw.png" style="width: 27rpx;height: 32rpx;"  mode=""></image>
			    <text>兑好礼</text>
			</view>
		</view>
		<view class="sign_in">
			<view class="sign_in_title">
				<text>已连续签到</text>
				<text style="color: #FB5225;margin:0 10rpx;">{{SigninRule.signinDays}}</text>
				<text>天</text>
			</view>
			<view class="sign_in_content">
				<view class="sign_in_item_out">
					<view class="sign_in_item" v-for="(item,index) in SigninRule.signinRules" :key="index">
						<view class="sign_in_icon" :class="{'active':item.isClick}">
							<image :src="item.isClick?urlActive:url" style="width: 39rpx;height: 39rpx;" mode=""></image>
							<text class="count">+{{item.ruleIntegral}}</text>
						</view>
						<text>{{getDay(item.ruleContent)}}</text>
					</view>
				</view>
				
				<view class="qiandao_btn noActive" v-if="SigninRule.signinStatus==0">
					签到
				</view>
				<view class="qiandao_btn" v-else @click="userSigninFun">
					签到
				</view>
			</view>
		</view>
		<view class="use_methods">
			<view class="use_methods_item" v-for="(item,index) in bookList" :key="index" @click="goDetail(item.id)">
				<view class="use_methods_lf">
					<image :src="item.icon" mode=""></image>
					<text>{{item.bookTitle}}</text>
				</view>
				
				<uni-icons type="arrowright" color="#666666" size="16"></uni-icons>
			</view>
			<view class="use_methods_item" @click="pointsDetails">
				<view class="use_methods_lf" >
					<image src="../../static/img/shop_jf.png" mode=""></image>
					<text>收益明细</text>
				</view>
				
				<uni-icons type="arrowright" color="#666666" size="16"></uni-icons>
			</view>
			<view class="use_methods_item" @click="goWithdrawal()">
				<view class="use_methods_lf" >
					<image src="../../static/img/jf_detail.png" mode=""></image>
					<text>提现明细</text>
				</view>
				
				<uni-icons type="arrowright" color="#666666" size="16"></uni-icons>
			</view>
			
		</view>
		<view class="qiandao_module" v-if="qiandao_module">
			
			<view class="qiandao_content">
				<view class="bg_module">
					
				</view>
				<view class="qiandao_content_item">
					<view v-for="(item,index) in list" :key="index" :class="{'qd_active':item.isClick}">
						<text>{{item.day}}</text>
						<image :src="item.isClick?urlActive:url"  mode=""></image>
						<text>+3</text>
					</view>
				</view>
				<view class="qd_module_btn">
					签到
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				url:"../../static/img/qiandao.png",
				urlActive:"../../static/img/qd_active.png",
				qiandao_module:false,
				
				list:[{
					day:"第一天",
					isClick:true,
				},{
					day:"第二天",
					isClick:true,
				},{
					day:"第三天",
					isClick:false,
				},{
					day:"第四天",
					isClick:false,
				},{
					day:"第五天",
					isClick:false,
				},{
					day:"第六天",
					isClick:false,
				},{
					day:"第七天",
					isClick:false,
				}],
				bookList:[],
				bookIcon:['../../static/img/my_jf.png'],
				SigninRule:{},
				userinfo:{},//用户信息
			}
		},
		
		onShow() {
			this.bookListFun();
			this.userSigninRule();
			this.getUserinfo()
		},
		methods:{
			//提现明细
			goWithdrawal(){
				uni.navigateTo({
				    url: '../mySub/WithdrawalDetails'
				});
			},
			//积分明细
			pointsDetails(){
				uni.navigateTo({
				    url: '../mySub/pointsDetails'
				});
			},
			//获取用户信息
			getUserinfo(){
				this.$http.get('/api/user/userInfo').then((data)=>{
					if(data.data.code==200){
						this.userinfo=data.data.result||{};
					}else{
						this.userinfo={};
					}
				})
			},
			//签到
			userSigninFun(){
				this.$http.get('/api/user/userSignin').then((data)=>{
					if(data.data.code==200){
						uni.showToast({
							title: '签到成功!',
							icon: "success",
							duration: 2000,
							
						});
						this.userSigninRule();
						this.getUserinfo()
					}else{
						uni.showToast({
							title: data.data.message,
							icon: "none",
							duration: 2000,
							
						});
					}
				})
			},
			getDay(num){
				return this.list[num-1].day;
			},
			// 文章列表
			bookListFun(){
				this.$http.get('/api/user/bookList/2').then((data)=>{
					if(data.data.code==200){
						this.bookList=data.data.result||[];
						this.bookList.forEach((a,i)=>{
							if(this.bookIcon[i]){
								a.icon=this.bookIcon[i];
							}
						})
					}else{
						this.bookList=[];
					}
				})
			},
			//获取签到规则
			userSigninRule(){
				this.$http.get('/api/user/userSigninRule').then((data)=>{
						if(data.data.code==200){
							this.SigninRule=data.data.result;
							this.SigninRule.signinRules.forEach((a,i)=>{
								if(this.SigninRule.signinDays==0){
									return ;
								}else if(i<this.SigninRule.signinDays){
									a.isClick=true;
								}
							})
						}else{
							this.SigninRule={};
						}
				})
			},
			goDetail(id){
				uni.navigateTo({
				    url: '../mySub/bookDetail?id='+id
				});
			}
		}
	}
</script>


<style lang="scss" scoped>
	@import '@/static/css/myIntegral.scss'
</style>

